package com.dongdongshop.operator.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.operator.pojo.TbSeller;
import com.dongdongshop.operator.service.SellerService;
import com.dongdongshop_util.Result;
import com.dongdongshop_util.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {

    private final Logger logger = LoggerFactory.getLogger(ItemCatController.class);

    @Reference(check = false)
    private SellerService sellerService;

    @RequestMapping("toSeller")
    public String toSeller(){
        return "admin/seller";
    }

    //获取商家管理表
    @ResponseBody
    @RequestMapping("getSeller")
    public Result getSeller(String name,String nickName,Integer status){
        try {
            List<TbSeller> sellerList = sellerService.getSeller(name,nickName,status);
            return Result.success(ResultEnum.SUCCESS,sellerList);
        } catch (Exception e){
            logger.error(String.valueOf(ResultEnum.FAIT),e);
            return Result.response(ResultEnum.FAIT);
        }
    }
    //根据id查看详情
    @ResponseBody
    @RequestMapping("getSellerById")
    public Result getSellerById(String sellerId){
        try {
            TbSeller tbSeller = sellerService.selectById(sellerId);
            return Result.success(ResultEnum.SUCCESS,tbSeller);
        } catch (Exception e){
            logger.error(String.valueOf(ResultEnum.FAIT),e);
            return Result.response(ResultEnum.FAIT);
        }
    }
    //审核状态
    @ResponseBody
    @RequestMapping("tongGuo")
    public Result tongGuo(String sellerId,Integer a){
        try {
            if (a == 1){
                sellerService.updateStatusById(sellerId,"1");
            }else if(a == 2){
                sellerService.updateStatusById(sellerId,"2");
            }else if(a == 3){
                sellerService.updateStatusById(sellerId,"3");
            }
            return Result.perfect(ResultEnum.SUCCESS);
        } catch (Exception e){
            logger.error(String.valueOf(ResultEnum.FAIT),e);
            return Result.response(ResultEnum.FAIT);
        }
    }
}
